package com.spring.arch;

import com.github.tobato.fastdfs.FdfsClientConfig;
import com.spring.arch.common.setup.ApplicationSetup;
import com.spring.arch.datasource.core.annotation.EnableMultiDatasource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

@SpringBootApplication
@EnableDiscoveryClient
@EnableCaching
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@Import(FdfsClientConfig.class)
@EnableFeignClients
@EnableHystrix
@EnableResourceServer
@EnableMultiDatasource(basePackages = "com.spring.arch.operation")
public class WebOperationStarterApplication implements CommandLineRunner {

    @Autowired
    private ApplicationSetup applicationSetup;

    @PostConstruct
    void init() {
        // 系统级设置
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
    }

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    public static void main(String[] args) {
        SpringApplication.run(WebOperationStarterApplication.class, args);
    }

    @Override
    public void run(String... args) {
        applicationSetup.init(args);
    }
}
